package com.xprime.mobileFramework.function;

import android.app.ProgressDialog;
import android.content.Context;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREInvalidObjectException;
import com.adobe.fre.FREObject;
import com.adobe.fre.FRETypeMismatchException;
import com.adobe.fre.FREWrongThreadException;

public class LoadingFREFunction implements FREFunction {

	private ProgressDialog loagindDialog; // Loading Dialog
	
	@Override
	public FREObject call(FREContext pContext, FREObject[] pParams) 
	{
		Context context = pContext.getActivity();
		
		try {
			
			Boolean isOn = pParams[0].getAsBool();
			String title = pParams[1].getAsString();
			String msg = pParams[2].getAsString();
			
			
			if( isOn )
			{
				loagindDialog = ProgressDialog.show(context, title,	msg, true, false);
				return FREObject.newObject("Loading ON!");
			}
			else
			{
				if( loagindDialog != null )
				{
					loagindDialog.dismiss();
					loagindDialog = null;
				}
				
				return FREObject.newObject("Loading OFF!");
			}
			
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (FRETypeMismatchException e) {
			e.printStackTrace();
		} catch (FREInvalidObjectException e) {
			e.printStackTrace();
		} catch (FREWrongThreadException e) {
			e.printStackTrace();
		}
		
		return null;
	}


}
